package com.mytx.search.config;


import com.alibaba.media.MediaConfiguration;
import com.alibaba.media.upload.UploadTokenClient;
import com.alibaba.media.upload.impl.DefaultUploadTokenClient;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import org.apache.http.HttpHost;
import org.aspectj.lang.annotation.Before;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * <p>搜索连接客户端</p>
 *
 * @author: XianGuo
 * @date: 2018年01月23日
 */
@Configuration
public class ElasticsConfig {

    @Value("${elasticsearch.host}")
    String host;
    @Value("${elasticsearch.port}")
    int port;
    String scheme= "http";

    /**
     * 初始化
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return getEsClientDecorator().getRestHighLevelClient();
    }

    @Bean
    @Scope("singleton")
    public ESClientDecorator getEsClientDecorator() {
        return new ESClientDecorator(new HttpHost(host, port,scheme));
    }


    @Value("${ali.url}")
    private String url;
    @Value("${ali.appKey}")
    private String appKey;
    @Value("${ali.secret}")
    private String secret;


    @Bean
    public TaobaoClient createTaoBaoClient() {

        return new DefaultTaobaoClient(url, appKey, secret);
    }

    @Bean
    public UploadTokenClient createWanTuTokenClient() {
        MediaConfiguration configuration = new MediaConfiguration();
        configuration.setAk(appKey);
        configuration.setSk(secret);
        configuration.setNamespace("mytx");
        return new DefaultUploadTokenClient(configuration);
    }


}
